package com.zhang;

import com.zhang.printer.BinaryTrees;

public class Main {

    public static void main(String[] args) {
//        test01();
//        test02();
//        test03();
        test06();
    }

    static void test01() {
        Integer[] dataArr = new Integer[]{
                38, 7, 49, 20, 39, 13, 16, 30, 46, 41, 48, 17, 43, 32, 14, 15, 36
        };
        BinarySearchTree2<Integer> bst = new BinarySearchTree2<>();
        for (Integer data : dataArr) {
            bst.add(data);
        }
        BinaryTrees.print(bst);
    }

    static void test02() {
        Integer[] data = new Integer[]{
                7, 4, 9, 2, 5, 8, 11, 3, 12, 1
        };
        BinarySearchTree2<Person> bst1 = new BinarySearchTree2<>();
        for (Integer datum : data) {
            bst1.add(new Person(datum));
        }
        BinaryTrees.print(bst1);
        System.out.println();
        BinarySearchTree2<Person> bst2 = new BinarySearchTree2<>((o1, o2) -> o2.getAge() - o1.getAge());
        for (Integer datum : data) {
            bst2.add(new Person(datum));
        }
        BinaryTrees.print(bst2);
    }

    static void test03() {
        Integer[] dataArr = new Integer[]{
                7, 4, 9, 2, 5, 8, 11, 3, 12, 1
        };
        BinarySearchTree2<Integer> bst = new BinarySearchTree2<>();
        for (Integer data : dataArr) {
            bst.add(data);
        }
        BinaryTrees.println(bst);
        bst.preorderTraversal();
        System.out.println("==========前序遍历==========");
        bst.inorderTraversal();
        System.out.println("==========中序遍历==========");
        bst.postorderTraversal();
        System.out.println("==========后序遍历==========");
        bst.levelOrderTraversal();
        System.out.println("==========层序遍历==========");
    }

    static void test04() {
        Integer[] dataArr = new Integer[]{
                7, 4, 9, 2, 5, 8, 11, 3, 12, 1
        };
        BinarySearchTree<Integer> bst = new BinarySearchTree<>();
        for (Integer data : dataArr) {
            bst.add(data);
        }
        BinaryTrees.println(bst);
        bst.levelOrder(element -> System.out.println(element + 1));
    }

    static void test05() {
        Integer[] dataArr = new Integer[]{
                7, 4, 9, 2, 5, 8, 11, 3, 12, 1
        };
        BinarySearchTree<Integer> bst = new BinarySearchTree<>();
        for (Integer data : dataArr) {
            bst.add(data);
        }
        BinaryTrees.println(bst);
        bst.preorder(element -> System.out.print(element + " "));
        System.out.println();
        bst.inorder(element -> System.out.print(element + " "));
        System.out.println();
        bst.postorder(element -> System.out.print(element + " "));
        System.out.println();
        bst.levelOrder(element -> System.out.print(element + " "));
        System.out.println();
    }

    static void test06(){
        Integer[] dataArr = new Integer[]{
                83, 16, 5, 72, 40, 92, 28, 32, 67, 68, 18, 70
        };
        BinarySearchTree2<Integer> bst = new BinarySearchTree2<>();
        for (Integer data : dataArr) {
            bst.add(data);
        }
        BinaryTrees.println(bst);
        bst.remove(83);
        System.out.println("====================");
        BinaryTrees.println(bst);
        bst.remove(40);
        System.out.println("====================");
        BinaryTrees.println(bst);
        bst.remove(70);
        System.out.println("====================");
        BinaryTrees.println(bst);
        bst.remove(67);
        System.out.println("====================");
        BinaryTrees.println(bst);
    }


}
